/*
 * Copyright 2011 Philippe Blanc.
 * 
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
 * use this file except in compliance with the License. You may obtain a copy of
 * the License at
 * 
 * http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations under
 * the License.
 */
package me.l1k3.fx.client.engine.impl;

import com.google.gwt.core.client.GWT;
import com.google.gwt.dom.client.Style;
import com.google.gwt.dom.client.Element;

import me.l1k3.fx.client.channel.inter.ChannelContext;
import me.l1k3.fx.client.channel.inter.ShowAndHide;

public final class ChannelContextImpl implements ChannelContext {
    private Element element;
    private Style style;
    private ShowAndHide hideAndShow;
    private double progress;
    
    @Override
    public final void setElement(Element element) {
        this.element = element;
        style = element.getStyle();
    }

    @Override
    public final Element getElement() {
        return element;
    }

    @Override
    public final Style getStyle() {
        return style;
    }

    @Override
    public final void enableShowAndHide() {
        if(hideAndShow==null) {
            hideAndShow = GWT.create(ShowAndHide.class);
            hideAndShow.init(element);
        }
    }

    @Override
    public final boolean isShowAndHide() {
        return hideAndShow!=null;
    }

    @Override
    public final void setVisible(boolean visible) {
        if(hideAndShow!=null) {
            if(visible) hideAndShow.show(style); else hideAndShow.hide(style);
        }
    }
    
    @Override
    public final void setProgress(double progress) {
        this.progress = progress;
    }

    @Override
    public final double getProgress() {
        return progress;
    }
}
